package com.林子祺.CAT旅游系统.view.tour.buy;

import com.林子祺.CAT旅游系统.controller.contentmanagement.OrderTicket;
import com.林子祺.CAT旅游系统.controller.contentmanagement.ShowTicket;
import com.林子祺.CAT旅游系统.entity.login.LoginStatus;
import com.林子祺.CAT旅游系统.entity.place.CurrentPlaceData;
import com.林子祺.CAT旅游系统.entity.place.PlaceData;
import com.林子祺.CAT旅游系统.view.Menu;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SearchTicket {

    static int number = 0;
    static int t = 1;

    public static void search(){
            JFrame jf = new JFrame("请输入要去的景点的id：");
            jf.setSize(500, 200);
            jf.setLocationRelativeTo(null);
            jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

            JPanel panel = new JPanel(null);

        // 表头（列名）
        Object[] columnNames = {"id","景点名称", "省份", "城市", "具体地址", "详细信息","价格"};

        // 表格所有行数据
        Object[][] rowData = {
                {"id","景点名称", "省份", "城市", "具体地址", "详细信息","价格"},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null},
                {null,null,null,null,null,null,null}
        };

        // 创建一个表格，指定 所有行数据 和 表头
        JTable table = new JTable(rowData, columnNames);
        table.setLocation(0,0);
        table.setSize(500,120);

        while (PlaceData.OutputData(number)) {
            table.getModel().setValueAt(CurrentPlaceData.id, t, 0);
            table.getModel().setValueAt(CurrentPlaceData.name, t, 1);
            table.getModel().setValueAt(CurrentPlaceData.provience, t, 2);
            table.getModel().setValueAt(CurrentPlaceData.city, t, 3);
            table.getModel().setValueAt(CurrentPlaceData.address, t, 4);
            table.getModel().setValueAt(CurrentPlaceData.detail, t, 5);
            table.getModel().setValueAt(CurrentPlaceData.price, t, 6);
            number++;
            t++;
        }
        number = t = 0;


        // 把 表头 添加到容器顶部（使用普通的中间容器添加表格时，表头 和 内容 需要分开添加）
        panel.add(table.getTableHeader());
        // 把 表格内容 添加到容器中心
        panel.add(table);

            final JTextField textField = new JTextField(8);
            textField.setLocation(0,130);
            textField.setSize(100,30);
            textField.setFont(new Font(null, Font.PLAIN, 12));
            panel.add(textField);

            JButton btn = new JButton("提交");
            btn.setLocation(110,130);
            btn.setSize(70,30);
            btn.setFont(new Font(null, Font.PLAIN, 10));
            btn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String s = textField.getText();
                    int MyInt = Integer.parseInt(s);
                    ShowTicket.show(MyInt);
                    jf.dispose();
                }
            });
            panel.add(btn);

        JButton btn1 = new JButton("返回");
        btn1.setLocation(190,130);
        btn1.setSize(70,30);
        btn1.setFont(new Font(null, Font.PLAIN, 10));
        btn1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Menu.menu();
                } catch (AWTException ex) {
                    throw new RuntimeException(ex);
                }
                jf.dispose();
            }
        });
        panel.add(btn1);

            jf.setContentPane(panel);
            jf.setVisible(true);
        }
    }
